package com.kpatil.erp.core.measure;

import com.kpatil.erp.common.HasParent;

public final class DerivedUnit extends UnitOfMeasure implements
		HasParent<UnitOfMeasure> {

	private double ratio = 1.0d;
	private UnitOfMeasure parent;

	public DerivedUnit(String name, UnitOfMeasure base, double ratio) {
		this.parent = base;
		this.ratio = ratio;
		setName(name);
		setType(base.getType());
		setPrecision(base.getPrecision());
	}

	public void setRatio(double ratio) {
		this.ratio = ratio;
	}

	public double getRatio() {
		return ratio;
	}

	@Override
	public double getUnit() {
		return parent.getUnit() * ratio;
	}

	public void setParent(UnitOfMeasure parent) {
		this.parent = parent;
	}

	public UnitOfMeasure getParent() {
		return parent;
	}

}
